package StructuralPattern.Facade;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class XMLUtil {
    public static Object getBean() {
        try {
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document document = documentBuilder.parse("src\\main\\resources\\config.xml");

            NodeList facadeClassName = document.getElementsByTagName("FacadeClassName");
            Node node = facadeClassName.item(0).getFirstChild();
            String value = node.getNodeValue();

            Class<?> aClass = Class.forName(value);
            Object o = aClass.newInstance();
            return o;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
}
